#ifndef __CREADSTREAM_H
#define __CREADSTREAM_H
static const int DEFAULT_BUFSIZE = 16;
typedef streambuf::int_type int_type;
class CReadBuf : public streambuf{
	public:
		CReadBuf(int _fd, int _buf_size = DEFAULT_BUFSIZE):	
			mFd(_fd), mBufSize(_buf_size){
			mBuf = (char *) malloc(mBufSize);
			if(mBuf == NULL)
				abort();
			setp(mBuf, mBuf + mBufSize );
		}
	protected:
		virtual int_type overflow(int_type c);
		virtual streamsize xsputn(const char *s, streamsize n);
		virtual int sync();
	private:
		void flushBuf();
	private:
		char *mBuf;
		int mFd;
		int mBufSize;
};
class CReadStream : public ostream{
	public :
		CReadStream(int _fd, int _bufSize): buf(_fd, _bufSize), ostream(&buf){
		}
	private:
		CReadBuf buf;
};
#endif
